﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chowpoo.Sql;
using CourseSystem.Core.Entities;
using CourseSystem.Core.SqlServerDAL;

namespace CourseSystem.Core.BLL
{
    public class QuestionLibBLL : CommonBLL<QuestionLibInfo, QuestionLibDAL>
    {

        public static IQueryable<QuestionLibInfo> GetList(string search, int sectionId, int ddlQtType, double ddlMinDiff, double ddlMaxDiff)
        {
            var re = GetList();
            if (!string.IsNullOrEmpty(search))
            {
                re = re.Where(o => o.Title.Contains(search));
            }
            if (sectionId != 0)
                re = re.Where(o => o.SectionId == sectionId);
            if (ddlQtType != -1)
                re = re.Where(o => o.Type == ddlQtType);
            if (ddlMinDiff != -1)
                re = re.Where(o => o.DiffCoe >= ddlMinDiff);
            if (ddlMaxDiff != -1)
                re = re.Where(o => o.DiffCoe <= ddlMaxDiff);
            return re;
        }

        public static QuestionLibInfo Get(int id)
        {
            using (var dal = new QuestionLibDAL())
            {
                var re = dal.SelectSingle(o => o.Id == id);
                return re;
            }
        }
        public static bool Del(int id)
        {
            using (var dal = new QuestionLibDAL())
            {
                return dal.Delete(o => o.Id == id) != null;
            }
        }

    }
}
